package com.api.shopapi.mapper;

import com.api.shopapi.entity.OrderLogistics;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface OrderLogisticsMapper {

    @Insert("insert into order_logistics (OrderLogisticsCode,OrderBusinessCode,SendTime,ExpressNumber,Remarks,ReceiveTime) values " +
            "(#{orderLogistics.OrderLogisticsCode},#{orderLogistics.OrderBusinessCode},#{orderLogistics.SendTime}," +
            "#{orderLogistics.ExpressNumber},#{orderLogistics.Remarks},#{orderLogistics.ReceiveTime})")
    int insert(@Param("orderLogistics") OrderLogistics orderLogistics);

    @Update("update order_logistics set OrderBusinessCode=#{orderLogistics.OrderBusinessCode},SendTime=#{orderLogistics.SendTime}," +
            "ExpressNumber=#{orderLogistics.ExpressNumber},Remarks=#{orderLogistics.Remarks},ReceiveTime=#{orderLogistics.ReceiveTime} " +
            "where OrderLogisticsCode=#{orderLogistics.OrderLogisticsCode}")
    int update(@Param("orderLogistics") OrderLogistics orderLogistics);

    @Select("select * from order_logistics where OrderLogisticsCode=#{orderLogisticsCode} limit 1")
    OrderLogistics getByOrderLogisticsCode(String orderLogisticsCode);

    @Select("<script>" +
            "select * from order_logistics ol LEFT JOIN order_business ob on ol.OrderBusinessCode=ob.OrderBusinessCode " +
            "left join `order` o on o.OrderCode=ob.OrderCode where 1=1" +
            " <if test ='userCode !=null and userCode!=\"\"  '>" +
            "  and o.UserCode =#{userCode}  " +
            " </if>" +
            " <if test ='businessCode !=null and businessCode!=\"\"  '>" +
            "  and ob.BusinessCode =#{businessCode}  " +
            " </if>" +
            "</script> ")
    List<OrderLogistics> getPageList(@Param("userCode")String userCode,@Param("businessCode") String businessCode);

    @Select("select * from order_logistics where OrderBusinessCode=#{orderBusinessCode} limit 1")
    OrderLogistics getByOrderBusinessCode(@Param("orderBusinessCode") String orderBusinessCode);
}
